"""This module provides useful methods relative to the networks.
"""

import commands


def ping(ip_address, count=1, timeout=4, deadline=4):
  """Returns True if machine replies, False otherwise.
  Arguments:
    ip_address: string, ip you want to ping.
    count: optional int, how many ping requests ?
    timeout: optional, int (seconds), how long are you willing to wait for one 
             result?
    deadline: optional, int (seconds), how long are you willing to wait for 
              the total result?
  """
  comm = "ping -q -c %i -n -w %i -W %i %s" % \
         (count, deadline, timeout, ip_address)
  status, output = commands.getstatusoutput(comm)
  return status == 0
  